<template>
	<view :class="!param?'content':'emergency_box'">
		<view class="app-title ac" v-if="!param">
			<view class="fl" @click="back">
				<image class="back" src="/static/img/back.png"></image>
			</view>
			{{creared?"创建工单":'工单详情'}}
		</view>

		<view class="top-bg" v-if="!param"></view>
		<view :class="!param?'body_box':'emergency_body_box'">

			<view class='body_box_content'>
				<scroll-view scroll-y="true" class="scroll-Y">
					<view class="list-area">
						<u-cell-group>
							<view class="list-item-title">基本信息</view>
							<u-cell-item title="工单类别:" required
								:value="listOrderData.woCategory == '' ? '请选择' : listOrderData.woCategory" @click="selece_type='orderType'
								   creared ?show_picker = true :'';
								    columns = workOrderType;
								    label_name = 'value';
								    value_name = 'code';">
							</u-cell-item>
							<!-- 			<u-field :disabled="true" v-model="listOrderData.woCategory" label="工单类别:"
								placeholder="请填写"></u-field> -->
							<u-field :disabled="true" v-model="listOrderData.woSn" label="工单编号:"
								placeholder="请填写"></u-field>
							<u-field :disabled="true" v-model="listOrderData.releaseTime" label="发布时间:"
								placeholder="请填写"></u-field>
							<!-- 		<u-cell-item title="发布时间:"
								:value="listOrderData.releaseTime == '' ? '请选择' : listOrderData.releaseTime" @click="
							  typeid==2&&editStatus ?show_date = true :'';
								date_type = 'relaseTime';">
							</u-cell-item> -->
							<view class="rowClass">
								<u-cell-item required title="专业"
									:value="listOrderData.major == '' ? '请选择' : returChName(listOrderData.major,workProfession)" @click="
									selece_type='major';
									typeid==2&&editStatus ?show_picker = true:'';
									columns = workProfession;
									label_name = 'value';
									value_name = 'code';">
								</u-cell-item>
								<u-cell-item required title="线路"
									:value="listOrderData.woLineName == '' ? '请选择' : listOrderData.woLineName" @click="
									selece_type='line';
									typeid==2&&editStatus ?show_picker = true :'';
									columns = lineTree;
									label_name = 'name';
									value_name = 'idK';">
								</u-cell-item>
							</view>
							<view class="rowClass">
								<u-cell-item required title="机构:" :value="listOrderData.managementOrgName == '' ? '请选择' : listOrderData.managementOrgName
									" @click="typeid==2&&editStatus ?showORG():''">
								</u-cell-item>
								<u-cell-item title="工单负责人"
									:value="listOrderData.woLeaderName == '' ? '请选择' : listOrderData.woLeaderName"
									@click="
									selece_type='leader';
									typeid==2&&editStatus&&peopleStatu() ?show_picker = true :'';
									columns = leaderOptions;
									label_name = 'name';
									value_name = 'idK';">
								</u-cell-item>
							</view>
							<u-cell-item required title="所在地点"
								:value="listOrderData.locationName == '' || listOrderData.locationName == 'null' ? '请选择' : listOrderData.locationName"
								@click="typeid==2&&editStatus ?show_station = true:''">
							</u-cell-item>
							<u-cell-item v-if='listOrderData.constructArea||creared' title="施工区域"
								:value="listOrderData.constructArea == '' ? '请选择' : listOrderData.constructArea"
								@click=" typeid==2&&editStatus ?show_Area = true:'';">
							</u-cell-item>
						</u-cell-group>
						<u-cell-item title="开始时间:" required
							:value="listOrderData.startTime == '' ? '请选择' : listOrderData.startTime" @click="
								typeid==2&&(editStatus||paifaStatus) ?show_date = true:'';
								date_type = 'startTime';">
						</u-cell-item>
						<u-cell-item :border-bottom="false" title="结束时间:" required
							:value="listOrderData.endTime == '' ? '请选择' : listOrderData.endTime" @click="
								typeid==2&&(editStatus||paifaStatus) ?show_date = true:'';
								date_type = 'endTime';">



							<!--  -->
						</u-cell-item>


						<view v-if="typeid==2" class="tips">
							* 请检查工单开始时间和结束时间是否正确。
						</view>


						<u-field v-if='listOrderData.constructArea||creared' :label-width='70'
							:disabled="typeid!=2?true:!editStatus" input-align="right"
							v-model="listOrderData.constructContent" label="施工内容:" placeholder="请填写"
							type="textarea"></u-field>
						<u-cell-group>
							<u-cell-item :border-top="true" :title="'作业任务'+taskNum" arrow-direction="down" :arrow="false">
								<view slot="right-icon" class="tools">
									<text @click="viewTask">查看/执行</text>
									<text v-if="typeid==2&&(editStatus||paifaStatus)" @click="editTask()"> | 修改</text>
								</view>
							</u-cell-item>
						</u-cell-group>
						<u-field v-if='listOrderData.constructArea||creared' :label-width='100'
							:disabled="typeid!=2?true:!editStatus" input-align="right"
							v-model="listOrderData.influenceArea" label="施工影响范围:" placeholder="请填写"
							type="textarea"></u-field>
						<u-cell-group>
							<u-cell-group>
								<u-cell-item title="作业人数" arrow-direction="down" :arrow="false">
									<!-- typeid!=2?true:!editStatus -->
									<view slot="right-icon"><u-number-box :disabled="!peopleStatu()"
											v-model="listOrderData.personNumber"></u-number-box></view>
								</u-cell-item>
							</u-cell-group>
							<u-cell-item title="作业人员" :value="listOrderData.constructPersonName"
								@click="typeid==2&&editStatus&&peopleStatu() ?show_people = true:''">

							</u-cell-item>
							<u-cell-item :title="'工器具'+(toolNum)" arrow-direction="down" :arrow="false">
								<view slot="right-icon" class="tools">
									<text @click="viewtool">查看</text><text v-if="typeid==2&&(editStatus||paifaStatus)"
										@click="edittool()"> | 修改</text>
								</view>
							</u-cell-item>
							<!-- <u-field v-model="listOrderData.constructPersonName" label="点单编号:"
								placeholder="请填写"></u-field>
							<u-cell-item title="点单开始时间:"
								:value="listOrderData.taskStartTime == '' ? '请选择' : listOrderData.taskStartTime" @click="
								show_date = true;
								date_type = 'orderStartTime';">
							</u-cell-item>

							<u-cell-item title="点单结束时间:"
								:value="listOrderData.taskStartTime == '' ? '请选择' : listOrderData.taskStartTime" @click="
								show_date = true;
								date_type = 'orderEndTime';">
							</u-cell-item> -->
							<!-- <view class="list-item-title">工单审核</view> -->
							<!-- 		<u-field :label-width='100' input-align="right" v-model="listOrderData.completenote"
								label="工单完成情况:" placeholder="请填写" type="textarea"></u-field>
							<view class="complete">
								<view>
									<view>
										<text>完成度</text>
									</view>
									<view>
										<u-slider v-model="value" :use-slot="true">
											<view class="">
												<view class="badge-button">
													{{value}}
												</view>
											</view>
										</u-slider>
									</view>
								</view>
								<hr />
							</view> -->
							<!-- <u-field v-model="listOrderData.statusName" label="质量确认人:" placeholder="请填写"></u-field> -->
							<u-field :disabled="true" class="lastField" v-model="listOrderData.woState" label="工单状态:"
								placeholder=""></u-field>
						</u-cell-group>

						<view class="upView">
							<u-field v-if="control&&typeid==2&&listOrderData.woState=='待提交'" :label-width='70'
								:disabled="typeid!=2" input-align="right" v-model="listOrderData.constructContent"
								label="检修说明:" placeholder="请填写" type="textarea"></u-field>
							<htz-image-upload v-if="control&&typeid==2&&listOrderData.woState=='待提交'" ref="uploadchild"
								:max="5" :mediaType='uploadMediaType' :formData='uploadformData' v-model="uploadData"
								:uploadSuccess="uploadSuccess" @imgDelete='imgDeleteCallback' :action="uploadUrl">
							</htz-image-upload>
							<view v-if="typeid!=2" class="photo-upload">
								<view v-for="(item, index) in uploadData" :key="index">
									<u-image width="70px" height="70px" :src="item"
										@click="imgPreview(index,uploadData)"></u-image>
								</view>
							</view>
						</view>

						<view v-if="listOrderData.woState=='已提交'&&typeid==2" class="list-item-title">当前操作</view>
						<u-radio-group v-if="listOrderData.woState=='已提交'&&typeid==2" size="32" shape='square'
							v-model="approveFlag" @change="radioGroupChange">
							<u-radio name="true">通过</u-radio>
							<u-radio name="false">不通过</u-radio>
						</u-radio-group>
						<u-field v-if="listOrderData.woState=='已提交'&&typeid==2" :label-width='100' input-align="right"
							v-model="remark" label="流转说明:" placeholder="请填写" type="textarea"></u-field>

						<!--结束检卡控暂存 -->
						<u-field v-if="false&&listOrderData.woState=='待提交'&&typeid==2" :label-width='100'
							:disabled="typeid!=2?true:!editStatus" input-align="right" v-model="checkRemark"
							label="检修说明:" placeholder="请填写" type="textarea"></u-field>

					</view>

				</scroll-view>
				<view class="footer" v-if="typeid==2">
					<u-button v-for="(item,index) in operationBtn" :disabled="item.disabled" :custom-style="customStyle"
						type="primary" size="medium" :ripple="true"
						@click="operationBtnClick(item,index)">{{item.displayNameCn}}</u-button>
				<!-- 	<u-button v-if="otherStatus(1)" :custom-style="customStyle" type="primary" size="medium"
						:ripple="true" @click="startCheck">开始检修</u-button>
					<u-button v-if="otherStatus(2)" :custom-style="customStyle" type="primary" size="medium"
						:ripple="true" @click="endCheck">结束检修</u-button> -->
				</view>
			</view>
		</view>

		<u-select v-model="show_picker" :list="columns" :label-name="label_name" :value-name="value_name"
			@confirm="onConfirm" @cancel="onCancel">
		</u-select>
		<u-picker v-model="show_date" mode="time" :params="params" @confirm="setDate" @cancel="onCancel"></u-picker>
		<SelectStation v-if="show_station" :stationName="listOrderData.locationName" :station="station_options"
			@close="show_station = false" @setStation="setStation"></SelectStation>
		<!-- <u-select v-model="teamName_select" mode="mutil-column-auto" :label-name="label_name" :value-name="value_name"
			:list="reeByOrgnum" @confirm="confirm"></u-select> -->
		<SelectPeople v-if="show_people" :peopleName="listOrderData.constructPersonName" :people="leaderOptions"
			@close="show_people = false" @setPeople="setPeople"></SelectPeople>

		<SelectArea v-if="show_Area" :constructAreaName="listOrderData.constructArea" :constructArea="workArea"
			@close="show_Area = false" @setArea="setArea"></SelectArea>
		<!-- 施工区域 -->

		<!-- 选择机构 -->
		<ljs-treeChoose :data="departList" @getChooseValue="orgchange" @close="orgcancle" v-if="orgShow" />
		<!-- 工器具 -->
		<toolDevice @passToolsData="acceptToolsData" :toolConfig="toolConfig" :show.sync="toolsDevicShow"></toolDevice>
		<!-- 任务详情 -->
		<taskDetail v-if="taskShow" @passTaskData="acceptTaskData" :taskConfig="taskConfig" :taskParam="taskParam"
			:show.sync="taskShow"></taskDetail>
		<u-modal v-model="showControl" width="auto" :title-style="titleStyle" :content-style="modelContent"
			:show-confirm-button="false" :show-cancel-button="true" :show-title="true" :mask-close-able="true">
			<view class="slot-content">
				<rich-text :nodes="description"></rich-text>

			</view>
		</u-modal>
	</view>
</template>

<script>
	import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
	import {
		PMS_DICT_CONTROLLER,
		WORK_CONTROLLER
	} from "../../api/pms";
	import toolDevice from "../../components/myWork/viewWork/toolDevice.vue";
	import taskDetail from "../../components/myWork/viewWork/task.vue";
	import SelectStation from "../../components/myWork/viewWork/selectStation";
	import SelectPeople from "../../components/myWork/viewWork/selectPeople.vue";
	import SelectArea from "../../components/myWork/viewWork/selectArea.vue";
	import {
		mapState
	} from "vuex";
	export default {
		components: {
			toolDevice,
			SelectStation,
			taskDetail,
			SelectPeople,
			SelectArea
		},
		props: {
			param: {

			},
			emergenceInfo: {},
			orderInfo: {}
		},
		data() {
			return {
				value: 20,
				departList: [],
				orgShow: false,
				toolConfig: {
					title: '工器具详情',
					type: "view",
					data: []
				},
				taskConfig: {
					title: '工作详情',
					type: "view",
					data: []
				},
				toolsData: [],
				station_options: [],
				people_options: [],
				customStyle: {
					// backgroundColor: "#15c6ac",
					width: "40%",
				},
				detailData: {},
				listOrderData: {

				},
				columns: [],
				type: true,
				show_picker: false,
				show_date: false,
				label_name: "",
				value_name: "",
				selece_type: "", // 下拉框类型
				toolsDevicShow: false, // 工器具 弹框
				taskShow: false, // 具体任务详情
				show_station: false,
				show_people: false,
				show_Area: false,
				teamName_select: false, // 显示班组级联框
				leaderOptions: [], //工单人员列表
				operationBtn: [

				], // 操作按钮
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true,
				},
				taskParam: {
					stations: [],
					startTime: "", // 工单开始时间
					woState: '',
					typeid: ''
				},
				woSn: '',
				typeid: "",
				pmsWoDetailed: [], // 任务详情
				pmsWoTools: [], // 工器具 
				remark: '', // 处理意见
				editStatus: true,
				paifaStatus: false,
				referce: false,
				approveFlag: true,
				creared: '',
				modelshow: false,
				checkRemark: '',
				contentStyle: {
					borderBottom: '1px solid red'
				},
				uploadMediaType: "image",
				uploadformData: {},
				uploadData: [],
				uploadUrl: '',
				control: false,
				showControl: false,
				modelContent: {
					padding: "15px"
				},
				titleStyle: {
					paddingTop: "16px",
					fontWeight: 600,
				},
				description: "",
				config: {
					pmsEquControl: '',
					pmsNfcShow: "",
					pmsScanCode: "",
					woSn: ''
				},
				taskNum:'',
				toolNum:'',
			}

		},
		computed: {
			...mapState([
				"workOrderType",
				"workProfession",
				"workOrderState",
				"lineTree",
				"reeByOrgnum",
				"workArea"
			]),
		},
		watch: {
			orderInfo: {
				async handler(newval) {
					if (newval && newval.woSn) {
						this.woSn = this.orderInfo.woSn
						await this.initDetail()
					}
				},
				deep: true,
				immediate: true
			}
		},
		onShow() {
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			if (this.referce) {
				// 重新获取数据
				this.initDetail() //获取列表数据
				// 每一次需要清除，否则会参数会缓存
				this.referce = false
			}
		},
		async onLoad(options) {
			this.woSn = options.woSn;
			this.typeid = options.typeid
			this.creared = options.created
		},
		async created() {
			if (!this.param && !this.creared) {
				await this.initDetail()
				await this.getNameByOrgId()
				await this.handleLine()
				await this.getWonOper()
				this.computedEditStatus()
			} else if (this.creared) {
				this.typeid = 2
			}
			this.uploadUrl = this.$store.state.baseEmerUrl + '/emergency/adviceDataAdd'
			await this.getSelecConfig()
		},
		onBackPress(e) {
			uni.switchTab({
				url: '/pages/productCenter/list'
			});
		},
		methods: {
			returChName(value,options){
				let name
				let filterArr =  options.filter(item=>item.code==value)
				filterArr.length? name = filterArr[0].value :name = value
				 // options.filter(item=>item.code==value)[0].value
				 
				 return name
			},
			// 接口获取显示按钮
			getSelecConfig() {
				this.fetch(
					"POST",
					this.$store.state.baseUrl + WORK_CONTROLLER.Post_Operation_SelectConfig, {}, false
				).then((res) => {
					if (res?.returnCode == '2004') {

						this.config.pmsEquControl = res.data.pmsEquControl
						this.config.pmsNfcShow = res.data.pmsNfcShow
						this.config.pmsScanCode = res.data.pmsScanCode
						this.butSelect = res.data.pmsEquControl

					}
				})
			},
			imgPreview(index, images) {
				uni.previewImage({
					urls: images,
					current: index,
					loop: true,
				});
			},
			uploadSuccess(res) {
				if (res.statusCode == 200 && res.data) {
					let photoID = JSON.parse(res.data).data.fileId;
					console.log('res', res)
					let url = this.$store.state.baseEmerUrl + '/emergency/adviceDataPreview?id=' + photoID
					return {
						success: true,
						url
					}
				} else {
					return {
						success: false,
						url: ''
					}
				}
			},
			imgDeleteCallback({
				del: del,
				tempFilePaths: tempFilePaths
			}) {
				console.log('del===del', del)
				let photoID = del.split("id=")[1];
				this.deleteFile(photoID)
			},
			deleteFile(fileID) {
				this.fetch('POST', this.$store.state.baseEmerUrl + `/emergency/deleteAdviceData/${fileID}`, {}, false)
					.then((
						res) => {
						if (res.data == '"success"') {
							console.log("该图片删除成功！");
						}
					})
			},
			radioGroupChange(e) {
				console.log(this.approveFlag);
			},
			peopleStatu() {
				if (this.creared) {
					return true
				} else {
					return false
				}
			},
			computedEditStatus() {
				let woState = this.listOrderData.woState
				let arr = [null, '草稿', '待接单', '准备中', '进行中', '待提交']
				arr.includes(woState) ? this.editStatus = true : this.editStatus = false
			},
			editWon() {
				this.newSave();
			},
			// 开始检修
		  async 	startCheck() {
				this.fetch("post", this.$store.state.baseUrl + WORK_CONTROLLER.POST_START, {
					woSn: this.listOrderData.woSn
				}, false).then((res) => {
					if (res.success) {
						uni.showToast({
							title: "开始检修成功",
							icon: "none",
						});
						this.initDetail()
						this.getWonOper()
					} else {
						uni.showToast({
							title: "开始检修失败",
							icon: "none",
						});
					}
				});
			},
			// 结束检修
			async endCheck() {
				// this.config.pmsNfcShow = res.data.pmsNfcShow
				// this.config.pmsScanCode = res.data.pmsScanCode
				let status  = true
				if (this.config.pmsNfcShow || this.config.pmsScanCode) {
					await this.initDetail()
					let  endTime = this.pmsWoDetailed.map(item=>{
						return item.equDetailList
					}).flat(2).map(item=>{
						return item.endTime
					})
					  status = endTime.every(item=>item)
					console.log('this.pmsWoDetailed',status)
					
				}
				if(!status){
					uni.showToast({
						title: "存在未检修完成的设备",
						icon: "none",
					});
					return 
				}
				this.fetch("post", this.$store.state.baseUrl + WORK_CONTROLLER.POST_End, {
					woSn: this.listOrderData.woSn
				}, false).then((res) => {
					if (res.success) {
						uni.showToast({
							title: "结束检修成功",
							icon: "none",
						});
						this.initDetail()
						 this.back()
					} else {
						//   工单提交的时候，卡控设备需要
						if (res.code == 101200999) {
							this.description =
								`<span style="font-weight: 600;">${res.message}</span> 当前状态异常，请进行复检`

							this.showControl = true
							this.control = true
						} else {
							this.control = false
							uni.showToast({
								title: "结束检修失败",
								icon: "none",
							});
						}

					}
				});
			},
			// 其他工单 按钮显示判断
			otherStatus(param) {
				if (param == 1) {
					return this.listOrderData.woState == '准备中'
				} else if (param == 2) {
					return this.listOrderData.woState == '进行中' 
					//  取消只有工单负责人才可以结束检修的限制
					// && this
					// 	.listOrderData.woLeaderId == this.getUserId()
				} else if (param == 3) {
					let status = false
					let woState = this.listOrderData.woState
					let arr = ['草稿', "已创建", '待接单', '准备中', '进行中', '待提交']
					arr.includes(woState) ? status = true : status = false
					return status
				}
			},
			getNameByOrgId() {
				if (this.listOrderData.managementOrg) {
					this.fetch(
						"get",
						this.$store.state.baseUrl + WORK_CONTROLLER.GET_NAME_BY_ORGID, {
							num: this.listOrderData.managementOrg
						}
					).then((res) => {
						if (res?.success) {
							this.leaderOptions = res?.data;
						}
					});
				} else {
					this.leaderOptions = [];
				}
			},
			showORG() {
				let self = this;
				this.orgShow = true;
				self.departList = self.reeByOrgnum.map((org) => self.mapTree(org));
			},
			mapTree(org) {
				const haveChildren =
					Array.isArray(org.children) && org.children.length > 0;
				return {
					id: org.orgnum,
					label: org.text,
					openTag: false,
					choose: false,
					children: haveChildren ? org.children.map((i) => this.mapTree(i)) : [],
				};
			},
			orgchange(org, items) {
				this.listOrderData.managementOrgName = items[items.length - 1].label;
				this.listOrderData.managementOrg = items[items.length - 1].id;
				setTimeout(() => {
					this.orgcancle();
				}, 500);
				this.getNameByOrgId()
				this.listOrderData.woLeaderName = ''
				this.listOrderData.woLeaderId = ''
			},
			orgcancle() {
				this.orgShow = false;
			},
			setStation(obj) {
				this.listOrderData.locationName = obj.name.toString();
				this.listOrderData.location = obj.id.toString();
				this.show_station = false;
			},
			setPeople(obj) {
				this.listOrderData.constructPersonName = obj.name.toString();
				this.listOrderData.constructPerson = obj.id.toString();
				this.show_people = false;
			},
			setArea(obj) {
				this.listOrderData.constructArea = obj.name.toString();
				// this.listOrderData.constructPerson = obj.id;
				this.show_Area = false;
			},
			async operationBtnClick(param, index) {
				if (param.displayNameEn == 'distribute') { // 派发 走派发的页面
					this.assign()
					return
				}
				if (param.displayNameEn == 'update') { // 修改 走修改接口
					this.newSave()
					return
				}
				if (param.displayNameEn == 'start') {
					 this.startCheck()
					return 
				}
				if (param.displayNameEn == 'end') {
					this.endCheck()
					return 
				}
				await this.fetch("post", this.$store.state.baseUrl + `/api/work/task/${param.functionName}`, {
					woSn: this.listOrderData.woSn,
					message: this.remark ? this.remark : '',
					approveFlag: this.approveFlag,
				}).then((res) => {
					if (res.success) {
						uni.showToast({
							title: res.message,
							icon: "none",
						});
						this.operationBtn[index].disabled = true
						//  接单不跳转到工单列表页面，可以开始检修 后续的操作
						if (param.displayNameEn != 'receive') { // 接单
							uni.redirectTo({
								url: `/pages/productCenter/list?typeid=2`
							});
						} else {
							this.getWonOper()
						}
						this.control = false
					} else {

					}
				});
				await this.initDetail();
				this.$forceUpdate()
			},
			checkWoRequire() {
				if (!this.listOrderData.major ||
					!this.listOrderData.woLineName ||
					!this.listOrderData.managementOrgName ||
					!this.listOrderData.locationName || 
					!this.listOrderData.woCategory||
					!this.listOrderData.startTime ||
					!this.listOrderData.endTime ) {
					uni.showToast({
						title: "请填写必填项",
						icon: "none",
					});
					return false
				} else {
					return true
				}
			},
			newSave() {
				if (!this.checkWoRequire()) return
				if(new Date(this.listOrderData.startTime).getTime()> new Date(this.listOrderData.endTime).getTime()){
					uni.showToast({
						title: "开始时间不能大于结束时间",
						icon: "none",
					});
					return 
				}
				let param = {
					pmsWoDetailedWorkDOList: this.pmsWoDetailed,
					pmsWoToolsDOList: this.pmsWoTools,
					pmsWoinforDOList: this.listOrderData,
				};
				this.fetch("post", this.$store.state.baseUrl + WORK_CONTROLLER.POST_SAVE_PmsInfo, param).then((
					res) => {
					if (res.success) {
						uni.showToast({
							title: "保存成功",
							icon: "none",
						});
					} else {
						uni.showToast({
							title: "保存失败",
							icon: "none",
						});
					}
				});
			},
			assign() {
				this.$store.commit('setTaskList', this.listOrderData)
				this.$store.commit('setOrgPeople', this.listOrderData.constructPerson)
				this.$store.commit('setOrderPeople', this.leaderOptions)
				let taskStr = this.pmsWoDetailed.length && JSON.stringify(this.pmsWoDetailed) || []
				let toolStr = this.pmsWoTools.length && JSON.stringify(this.pmsWoTools) || []
				// 跳转到 分配设备的页面
				uni.navigateTo({
					// url: `/pages/productCenter/assigDevice?woSn=${this.listOrderData.woSn}&typeid=2`
					url: `/pages/productCenter/assigDevice?woSn=${this.listOrderData.woSn}&typeid=2&taskListStr=${taskStr}&toolListStr=${toolStr}`
				});
			},
			onConfirm(item) {
				switch (this.selece_type) {
					case "orderType":
						this.listOrderData.woCategory = item[0].label
						// this.listOrderData.orderTypeCode = item[0].value
						break;
					case "line":
						this.listOrderData.woLineName = item[0].label
						this.listOrderData.woLine = item[0].value
						this.handleLine(item) // 根据 地铁线路获取对应的站
						this.listOrderData.locationName = ''
						this.listOrderData.location = '';
						break;
					case "major":
						this.listOrderData.major = item[0].value
						// this.listOrderData.professionCode = item[0].value
						break;
					case "constrareaName":
						this.listOrderData.constructArea = item[0].label
						// this.listOrderData.constrareaCode = item[0].value
						break;
					case "leader":
						this.listOrderData.woLeaderName = item[0].label
						this.listOrderData.woLeaderId = item[0].value
						break;
					default:
				}
				this.onCancel();
			},
			onCancel() {
				this.show_picker = false;
				this.show_date = false;
				this.show_station = false;
			},
			handleLine(obj) {
				if (this.listOrderData.woLine) {
					this.fetch(
						"get",
						this.$store.state.baseUrl + PMS_DICT_CONTROLLER.GET_NAME_BY_LINEID, {
							lineId: obj ? obj[0].value : this.listOrderData.woLine
						}
					).then((res) => {
						if (res?.success) {
							this.station_options = res?.data;
						}
					});
				} else {
					this.station_options = [];
				}
			},
			setDate(obj) {
				let str = `${obj.year}-${obj.month}-${obj.day} ${obj.hour}:${obj.minute}:${obj.second}`
				this.listOrderData[this.date_type] = str
				this.onCancel();
			},
			// 查看工器具
			viewtool() {
				this.toolsDevicShow = true
				this.toolConfig.type = "view"
				this.toolConfig.title = "工器具详情"
				this.toolConfig.data = JSON.parse(JSON.stringify(this.pmsWoTools))
			},
			// 修改工器具
			edittool() {
				this.toolsDevicShow = true
				this.toolConfig.type = "edit"
				this.toolConfig.title = "修改工器具"
				this.toolConfig.data = JSON.parse(JSON.stringify(this.pmsWoTools))
			},
			acceptToolsData(val) {
				this.listOrderData.PmsWoTools = val
				this.pmsWoTools = val
				let totalNum = 0
				val.forEach(item=>{
					if(item.demandNumber){
						totalNum+= item.demandNumber
					}
				})
				if(val.length&&totalNum){
					this.toolNum = `(${totalNum}件)`
				}
			},
			// 查看任务
			viewTask() {
				// this.taskShow = true
				this.taskConfig.type = "view"
				this.taskConfig.title = "任务详情"
				this.taskConfig.data = JSON.parse(JSON.stringify(this.pmsWoDetailed))
				this.taskParam.typeid = this.typeid
				this.taskParam.woState = this.listOrderData.woState
				this.taskParam.woSn = this.woSn
				this.config.woSn = this.woSn
				this.config.woState = this.listOrderData.woState
				uni.navigateTo({
					url: '/pages/productCenter/deviceList?btn=' + this.typeid + "&type=view" + '&config=' + JSON
						.stringify(this.config)
				})
			},
			// 修改任务
			editTask() {
				this.taskShow = true
				this.taskConfig.type = "edit"
				this.taskConfig.title = "修改任务",
					this.taskConfig.data = JSON.parse(JSON.stringify(this.pmsWoDetailed))
				this.taskParam.stations = this.listOrderData.location
				this.taskParam.startTime = this.listOrderData.startTime
				this.taskParam.woState = this.listOrderData.woState
				this.taskParam.typeid = this.typeid
				this.taskParam.woSn = this.woSn
			},
			async acceptTaskData(val) {
				this.listOrderData.PmsWoDetailed = val
				this.pmsWoDetailed = val
				await this.newSave()
				await this.initDetail()
				this.taskConfig.data = JSON.parse(JSON.stringify(this.pmsWoDetailed))
			},
			back() {
				uni.navigateBack()
				// uni.navigateTo({
				// 	url: `/pages/productCenter/list?typeid=${this.typeid}`
				// });
			},
			getWonOper() {
				this.fetch('GET', this.$store.state.baseUrl + WORK_CONTROLLER.GET_WOSn_Oper, {
						woSn: this.woSn
					},
					false).then((res) => {
					if (res.success && res.data) {
						this.operationBtn = res.data
						this.operationBtn.forEach((item, index) => {
							if (item.displayNameEn == 'update') {
								// this.editStatus = true
								// this.operationBtn.splice(index, 1)
							}
							if (item.displayNameEn == 'receive' && this.listOrderData.woState !== '待接单') {
								// this.operationBtn.splice(index, 1)
							}
							if (item.displayNameCn == '派发') {
								this.paifaStatus = true
							}
						})
					} else {
						console.error(res)
					}
				})
			},
			async initDetail() {
				await this.fetch('GET', this.$store.state.baseUrl + WORK_CONTROLLER.GET_WoSn_DETAIL, {
						woSn: this.woSn,
						findAllTaskFlag:this.typeid==4
					},
					false).then((res) => {
					if (res.success && res.data) {
						this.listOrderData = res.data.PmsWoinfor
						this.pmsWoDetailed = res.data.PmsWoDetailed
						if(this.pmsWoDetailed.length){
							this.taskNum = `(${this.pmsWoDetailed.length}项)`
						}
						this.pmsWoTools = res.data.PmsWoTools
						this.acceptToolsData(this.pmsWoTools)
						
					} else {
						console.error(res)
					}
				})
			}
		}
	}
</script>

<style scoped lang="less">
	/deep/.htz-image-upload-Item {
		width: 70px;
		height: 70px;
	}

	.tips {
		color: red;
		font-size: 12px;
		padding: 5px 10px;
		border-bottom: 1px solid #f0f0f0;
	}

	/deep/.u-model__footer {
		border-top: 1px solid #f0f0f0;
	}

	.u-radio-group {
		padding: 10px 8px 0;
	}

	.rowClass {
		display: flex;
		flex-direction: row;

		&:nth-child(2) {
			// padding-left: 5px!important;
		}

	}

	.lastField::after {
		border-bottom: 0px;
	}

	/deep/ .u-cell {
		padding: 10px 2px !important;
	}

	.u-field {
		padding: 10px 2px 10px 8px !important;
	}

	/deep/.u-label {
		flex: 0 0 auto !important;

	}

	/deep/.u-cell--required:before {
		left: 2px;
	}

	/deep/.u-cell_title {
		color: #333;
		padding-left: 8px;
	}

	/deep/.u-cell__value {
		padding: 0 4px 0 8px;
	}

	.content {
		height: 100vh;
		width: 100%;
		// display: flex;
		// flex-direction: column;
		padding: 0 0rpx;
		overflow: hidden;
		// position: absolute;
	}

	.emergency_box {
		height: 100%;
	}

	.body_box {
		width: 95%;
		margin: 0 auto;
		background: #FFFFFF;
		position: relative;
		z-index: 100;
		height: calc(100vh - 100px);
		top: -100px;
		border-radius: 10px;
		padding: 10px 0;



	}

	.body_box_content {
		display: flex;
		flex-direction: column;
		height: 100%;
	}

	.scroll-Y {
		flex: 1;
		height: 0;
		padding: 0 20rpx;

	}

	.emergency_body_box {
		width: 95%;
		margin: 0 auto;
		height: 100%;
		// .body_box_content{
		// 	padding: 0 20rpx;
		// }

	}

	.footer {
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		flex-wrap: wrap;
		// margin-top: 10rpx;
		border-radius: 0, 0, 10px, 10px;
		border-top: 1px solid #f1f1f1;
		padding: 10px 20rpx 0px;
		box-shadow: 5px -1px 5px #f6f6f6;

		/deep/.u-btn {
			// margin: 10rpx 5%;
			// margin-right: 30rpx;
			width: 30% !important;
		}

		:last-child {
			// margin-right: 0px;
		}
	}

	.app-title {
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 99;
	}

	.list-area {
		hr {
			border: 0;
			border-top: 1px solid #F2F3F6;
		}

		.list-item-title {
			background-color: #f5f5f5;
			height: 70rpx;
			line-height: 70rpx;
			padding-left: 30rpx;
			font-size: 30rpx;
			color: #a7a7a7;
			font-weight: bold;

		}
	}

	:deep(.uni-input-input) {
		text-align: right;
	}

	/deep/.u-input__input {
		height: 100%;
	}

	.tools {
		color: #2979ff;

		text:nth-of-type(1) {
			padding-right: 6px;
		}

		text:nth-of-type(2) {
			padding-left: 0px;
		}
	}

	.wrap {
		padding: 30rpx;
	}

	.badge-button {
		padding: 4rpx 6rpx;
		background-color: #e4393c;
		color: #fff;
		border-radius: 10rpx;
		font-size: 22rpx;
		line-height: 1;
	}

	.complete {
		>view:nth-of-type(1) {

			padding: 26rpx 32rpx 26rpx 0;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;

			:nth-child(2) {
				// flex: 1;
				width: 60%;

			}
		}
	}
</style>